import path from "node:path";
import AutoImport from "unplugin-auto-import/vite";
import { defineConfig } from "vite";

type RelativeFilePath<T extends string> = string & { baseDir?: T };
function pwd2(p?: RelativeFilePath<"$dir/">) {
  if (p) {
    return path.resolve(import.meta.dirname, ".", p);
  }
  return path.resolve(import.meta.dirname, ".");
}

export default defineConfig({
  root: pwd2(),
  appType: "spa",
  experimental: {
    hmrPartialAccept: true,
  },
  assetsInclude: ["src/**/*.html"],
  // ssr: {
  //   target: "node",
  // },
  server: {
    port: 7367,
  },
  resolve: {
    alias: {
      "@": pwd2("src"),
      "#lit-comp": pwd2("lit-comp"),
      "#ngx-app": pwd2("app/ngx-app"),
      "@mf": pwd2("@mf-types"),
    },
    conditions: ["development", "import", "require"],
  },
  plugins: [
    AutoImport({
      imports: [
        {
          from: pwd2("prelude/index"),
          imports: ["html"],
        },
      ],
      dts: true,
    }),
  ],
});
